package coms.fourthirty.emm;

import java.util.ArrayList;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import coms.fourthirty.emm.resources.EMSResources;
import coms.fourthirty.emm.resources.Message;

public class EMSViewMessage extends Activity {
	private String username;
	private ArrayList<Message> msgs;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle grundle) {
		super.onCreate(grundle);
		setContentView(R.layout.view_message);

		Bundle extras = getIntent().getExtras();
		// username = extras.getString("coms.fourthirty.emm.username");
		username = EMSResources.username;
		msgs = EMSResources.msgs;
		String from, subject, body;
		int messageID = extras.getInt("coms.fourthirty.emm.messageID", 0);
		from = getMessageFrom(messageID);
		subject = getMessageSubject(messageID);
		body = getMessageBody(messageID);
		markAsRead(messageID);
		((EditText) findViewById(R.id.edit_text_view_message_from))
				.setText(from);
		((EditText) findViewById(R.id.edit_text_view_message_subject))
				.setText(subject);
		((EditText) findViewById(R.id.edit_text_view_message_body))
				.setText(body);

		if (from.equals("System"))
			findViewById(R.id.button_reply_to_message).setVisibility(
					View.INVISIBLE);
	}

	public void reply(View view) {
		String to, subject;
		to = ((EditText) findViewById(R.id.edit_text_view_message_from))
				.getText().toString();
		subject = ((EditText) findViewById(R.id.edit_text_view_message_subject))
				.getText().toString();

		if (!to.equals("System")) {
			Intent i = new Intent(EMSViewMessage.this, EMSNewMessage.class);
			// i.putExtra("coms.fourthirty.emm.username", username);
			i.putExtra("coms.fourthirty.emm.to", to);
			i.putExtra("coms.fourthirty.emm.subject", "RE:" + subject);
			startActivity(i);
		}
	}

	private String getMessageFrom(int id) {
		return msgs.get(id).from;
	}

	private String getMessageSubject(int id) {
		return msgs.get(id).subject;
	}

	private String getMessageBody(int id) {
		return msgs.get(id).body;
	}

	private void markAsRead(int id) {
		msgs.get(id).readed = true;
	}
}